﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Parallel3M.parallel3m.framework
{
    public class ParallelChannelSelector:ParallelProcessor
    {

        public ParallelConnection defaultConnection=null;
        //split the payload by routeTag
        public override void process()
        {
            foreach(ParallelConnection inputConnection in inputConnections)
            {
                ParallelPayload payload = inputConnection.Flowout();
                bool isFlowin = false;
                if (payload != null)
                {
                    payloadcount++;

                    foreach (ParallelConnection outputConnection in outputConnections)
                    {
                        if (defaultConnection == null && outputConnection.routeTag == PAYLOADCONSTRANT.DEFAULT_ROUTETAG)
                        {
                            defaultConnection = outputConnection;
                        }

                        if (outputConnection.routeTag == payload.routeTag)
                        {
                            isFlowin = true;
                            outputConnection.Flowin(payload);
                            break;
                        }
                    }

                    if (!isFlowin && defaultConnection!=null)
                    {
                        defaultConnection.Flowin(payload);
                    }

                }
            }
        }

        

    }
}
